# R2R Documentation

## Launching

This example runs a basic application, which launches a server to handle ingestion, embedding, and RAG. Further, it demonstrates how to interact with the local server using the [`R2RClient`](https://github.com/SciPhi-AI/R2R/blob/main/r2r/client/base.py)`.

```bash
# Launch the application
# If using a venv, replace `uvicorn` with `venv_path/bin/uvicorn`
uvicorn r2r.examples.basic.app:app
```

This launches a server which exposes the default pipeline. The settings of the pipeline are defined in the `config.json`. The default values for these settings are shown in the [config.json section](#configjson) below.
```python
# r2r.examples.basic.app
from r2r.main import E2EPipelineFactory

app = E2EPipelineFactory.create_pipeline()
```


## R2RClient Interface

The `R2RClient` provides an interface to interact with the server. Here are the main methods:

- `upload_and_process_file(document_id: str, file_path: str, metadata: Optional[dict] = None, settings: Optional[dict] = None) -> dict`: Uploads a file to the server and processes it. 

- `add_entry(document_id: str, blobs: Dict[str, str], metadata: Optional[Dict[str, Any]] = None, do_upsert: Optional[bool] = False, settings: Optional[Dict[str, Any]] = None) -> dict`: Adds an entry to the server. 

- `add_entries(entries: List[Dict[str, Any]], do_upsert: Optional[bool] = False, settings: Optional[Dict[str, Any]] = None) -> dict`: Adds multiple entries to the server. 

- `search(query: str, limit: Optional[int] = 10, filters: Optional[Dict[str, Any]] = None, settings: Optional[Dict[str, Any]] = None) -> dict`: Searches the server for a query. 

- `rag_completion(query: str, limit: Optional[int] = 10, filters: Optional[Dict[str, Any]] = None, settings: Optional[Dict[str, Any]] = None) -> dict`: Requests a RAG completion from the server. 

- `filtered_deletion(key: str, value: Union[bool, int, str]) -> dict`: Deletes entries from the server based on a filter. 

- `get_logs() -> dict`: Retrieves logs from the server. 

- `get_logs_summary() -> dict`: Retrieves a summary of logs from the server. 


## config.json
<a name="configjson"></a>


During the example pipeline creation a default `config.json` is loaded and passed to the pipeline. It provides settings for the following services:

- Database provider
- LLM settings
- Embedding settings
- Parsing logic
- and more.

The default values for the config are shown below. 

```json
{
  "database": {
    "provider": "local",
    "collection_name": "demo-v1-test"
  },
  "evals": {
    "provider": "deepeval",
    "frequency": 0.25
  },
  "embedding": {
    "provider": "openai",
    "model": "text-embedding-3-small",
    "dimension": 1536,
    "batch_size": 32
  },
  "text_splitter": {
    "chunk_size": 512,
    "chunk_overlap": 20
  },
  "language_model": {
    "provider": "litellm",
    "model": "gpt-4-0125-preview",
    "temperature": 0.1,
    "top_p": 0.9,
    "top_k": 128,
    "max_tokens_to_sample": 1024,
    "do_stream": false
  },
  "logging": {
    "provider": "local",
    "level": "INFO",
    "name": "r2r",
    "database": "demo_logs_v1"
  }
}
```

_Note: For a full list of options, see [Config Setup](../core_features/config.mdx)._

The pipeline is composed of three main components: `Ingestion`, `Embedding`, and `RAG` together with `Logging`.

To launch your own custom application pipeline, you may run with the following
```python

class E2EPipelineFactory:
    ...
    app = E2EPipelineFactory.create_pipeline(
        # override with your own custom ingestion pipeline
        ingestion_pipeline_impl=BasicIngestionPipeline,
        # override with your own custom embedding pipeline
        embedding_pipeline_impl=BasicEmbeddingPipeline,
        # override with your own custom RAG pipeline
        rag_pipeline_impl=BasicRAGPipeline,
        # override with your own config.json
        config_path=my_config.json,
    )
```

## Demo: Installation and launching Basic App & Client

[![demo_screenshot](../getting-started/demo_screenshot.png)](https://github.com/SciPhi-AI/r2r/assets/68796651/c648ab67-973a-416a-985e-2eafb0a41ef0)
